<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_QUESTION_MNG;
$page_pageId = PAG_QUESTION_UNRESOLVED_LIST;

require "../framepages/moudle_base.php";

?>
<div class="main-content">
    <div>
        <table class="table" style="word-break:break-all" style="width: 100%">
            <tr>
                <th width="4%">序号</th>
                <th width="4%">问题id</th>
                <th width="4%">用户id</th>
                <th width="18%">问题内容</th>
                <th width="12%">联系方式</th>
                <th width="12%">提问时间</th>
                <th width="12%">操作</th>
            </tr>

            <?php
            $page_index = $_GET['page_index'];
            if (!$page_index) {
                $page_index = 1;
            }
            $every_page_counts = 30;
            $list_start = ($page_index-1)*$every_page_counts;

            $question_list_array = \Data\Tree_question_DAO::getQuestionList(STATE_NO,$list_start,$every_page_counts);
            $question_list = $question_list_array[1];
            $total_count = $question_list_array[0];
            $page_count = ceil($total_count/$every_page_counts);
            $page_last = $page_index-1;
            $page_next = $page_index+1;
            $i = $list_start+1;
            foreach ($question_list as $question_record) {
                $question_id = $question_record->getQUESTION_ID();
                $customer_id = $question_record->getCUSTOMER_ID();
                $question_content = $question_record->getQUESTION_CONTENT();
                $contact_number = $question_record->getCONTACT_NUMBER();
                $created_on = $question_record->getCREATED_ON();
                echo "
                        <tr>
                            <td>$i</td>
                            <td>$question_id</td>
                            <td>$customer_id</td>
                            <td>$question_content</td>
                            <td>$contact_number</td>
                            <td>$created_on</td>
                            <td><button type='button' class='btn btn-danger' onclick='to_response($question_id)' >回复</button></td>                                                 
                        </tr>
                    ";
                $i++;
            }
            ?>

        </table>
    </div>
    <div style="margin-left:35%; margin-top:40px;">
        <div>
            <?php
            if ($page_last) {
                echo "            
                    <button onclick='last_page($page_last)'>上一页</button>                            
                ";
            }

            if ($page_next<=$page_count) {
                echo "         
                    <button onclick='next_page($page_next)'>下一页</button>               
                ";
            }

            if ($page_count>1) {
                echo "
                    &nbsp;&nbsp;&nbsp;&nbsp;去往第<input type='text' name='go_page' id='go_page' size='3'>页
                <button onclick='go_page()'>GO</button>
                    ";
            }
            ?>



        </div>

        <div style="margin-left:5%; margin-top:20px;">
            第<?php echo $page_index ?>页 &nbsp;&nbsp;&nbsp;&nbsp;
            共<?php echo $page_count ?>页  &nbsp;&nbsp;&nbsp;&nbsp;共<?php echo $total_count ?>条记录
        </div>


    </div>

    <?php
    require "../framepages/footer.php";
    ?>
</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    function to_response(question_id) {
        url = "question_to_response.php?question_id="+question_id;
        window.location.href = url;
    }

    function last_page(page_last) {
        url = "?page_index="+page_last;
        window.location.href = url;
    }

    function next_page(page_next) {
        url = "?page_index="+page_next;
        window.location.href = url;
    }

    function go_page()
    {
        url = "?page_index="+$('#go_page').val();
        window.location.href = url;
    }
</script>
</body>
</html>
